home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
CW GUSI 1.6.4
/
include
/
GUSIFile_P.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-10-15
|
6KB
|
226 lines
/*********************************************************************
Project : GUSI - Grand Unified Socket Interface
File : GUSIFile_P.h - Common Definitions for File Sockets
Author : Matthias Neeracher
Language : MPW C/C++
$Log: GUSIFile_P.h,v $
Revision 1.2 1994/12/31 02:04:05 neeri
Reorganize file name dispatching.
Revision 1.1 1994/08/10 00:40:37 neeri
Initial revision
*********************************************************************/
#include "GUSI_P.h"
extern int File_error(OSErr err);
extern Boolean IsDevice(const char * fn);
#ifndef PRAGMA_ALIGN_SUPPORTED
#error Apple had some fun with the conditional macros again
#endif
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=mac68k
#endif
class FileSocket : public Socket {
friend class FileSocketDomain;
protected:
short fRefNum;
Boolean append;
FileSocket(short fRefNum) : fRefNum(fRefNum) {}
void SetFRefNum(short fRefNum) { this->fRefNum = fRefNum; }
void PrepareWrite() { if (append) lseek(0, SEEK_END); }
public:
virtual int fcntl(unsigned int cmd, int arg);
virtual int ioctl(unsigned int request, void *argp);
virtual int fstat(struct stat * buf);
virtual int select(Boolean * canRead, Boolean * canWrite, Boolean * exception);
virtual ~FileSocket();
};
class MPWFileSocket : public FileSocket {
friend class FileSocketDomain;
friend class MPWDomain;
protected:
int fd;
MPWFileSocket(int fd);
static MPWFileSocket * open(const char * name, int flags);
static MPWFileSocket * stdopen(int fd);
public:
virtual int read(void * buffer, int buflen);
virtual int write(void * buffer, int buflen);
virtual int fcntl(unsigned int cmd, int arg);
virtual int ioctl(unsigned int request, void *argp);
virtual long lseek(long offset, int whence);
virtual int ftruncate(long offset);
virtual int fstat(struct stat * buf);
virtual int isatty();
virtual ~MPWFileSocket();
};
class MacFileSocket : public FileSocket {
friend class FileSocketDomain;
protected:
MacFileSocket(short fRef) : FileSocket(fRef) {}
static MacFileSocket * open(const TFileSpec & spec, int flags);
public:
virtual int read(void * buffer, int buflen);
virtual int write(void * buffer, int buflen);
virtual int ioctl(unsigned int request, void *argp);
virtual long lseek(long offset, int whence);
virtual int ftruncate(long offset);
virtual ~MacFileSocket();
};
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=reset
#endif
// FileSocketDomain is the spiritual leader for all domains that deal
// with file names. Descendants claim their interest in device names
// and normal names on creation.
// When their Yours() routine is called, they have to give a definite
// answer on whether they'll take responsibility for a given file/request
// combination. They have the right to cache information in static areas,
// as no second call to Yours() will be made before the actual routine is
// called.
class GUSIFileRef;
class FileSocketDomain : public SocketDomain {
friend SocketTable::SocketTable();
friend int SocketTable::Install(Socket * sock, int start);
FileSocketDomain * nextDeviceDomain;
FileSocketDomain * nextFileDomain;
protected:
static FileSocketDomain * firstDeviceDomain;
static FileSocketDomain * lastDeviceDomain;
static FileSocketDomain * firstFileDomain;
static FileSocketDomain * lastFileDomain;
FileSocketDomain(
int domain,
Boolean doesDevices,
Boolean doesFiles);
public:
FileSocketDomain();
virtual ~FileSocketDomain();
enum Request {
willOpen,
willRemove,
willRename,
willGetFileInfo,
willSetFileInfo,
willFAccess,
willStat,
willChmod,
willUTime,
willAccess
};
static FileSocketDomain * FindDomain(const GUSIFileRef & ref, FileSocketDomain::Request request);
virtual Boolean Yours(const GUSIFileRef & ref, FileSocketDomain::Request request);
virtual Socket * open(const GUSIFileRef & ref, int oflag);
virtual int remove(const GUSIFileRef & ref);
virtual int rename(const GUSIFileRef & ref, const char *newname);
virtual void
fgetfileinfo(
const GUSIFileRef & ref,
unsigned long * creator, unsigned long * type);
virtual void
fsetfileinfo(
const GUSIFileRef & ref,
unsigned long creator, unsigned long type);
virtual int
faccess(const GUSIFileRef & ref, unsigned int cmd, long* arg);
virtual int stat(const GUSIFileRef & ref, struct stat * buf);
virtual int chmod(const GUSIFileRef & ref, mode_t mode);
virtual int utime(const GUSIFileRef & ref, const struct utimbuf * times);
virtual int access(const GUSIFileRef & ref, int mode);
virtual int choose(
int type,
char * prompt,
void * constraint,
int flags,
void * name,
int * namelen);
};
// A GUSIFileRef is an immutable structure, consisting of a pointer to
// a path name, a pointer to a TFileSpec (if the path is a plain file),
// and a pointer to the FileSocketDomain which will handle it.
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=mac68k
#endif
class GUSIFileRef {
OSErr error;
Boolean hasInfo;
TFileSpec file;
CInfoPBRec info;
FileSocketDomain * domain;
public:
const char * name;
TFileSpec * spec;
GUSIFileRef(const char * name, FileSocketDomain::Request request, Boolean useAlias = false);
GUSIFileRef(short fRefNum, FileSocketDomain::Request request);
Boolean IsDevice() const { return !spec; }
OSErr Error() const { return error; }
const CInfoPBRec * Info() const; // conceptually const
FileSocketDomain * Domain() const { return domain; }
};
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=reset
#endif
extern FileSocketDomain * FileSockets;
class MPWDomain : public SocketDomain {
public:
MPWDomain();
static MPWFileSocket * (*open)(const char * name, int flags);
static MPWFileSocket * (*stdopen)(int fd);
};
extern MPWDomain MPWSockets;
//
// Null sockets always return EOF on reading and act as bottomless sinks on writing
//
class NullSocketDomain : public FileSocketDomain {
Socket * singleton;
public:
NullSocketDomain() : FileSocketDomain(AF_UNSPEC, true, false), singleton(nil) {}
virtual Boolean Yours(const GUSIFileRef & ref, FileSocketDomain::Request request);
virtual Socket * open(const GUSIFileRef & ref, int oflag);
};
__BEGIN_DECLS
int fwalk(int (*func)(FILE * stream));
typedef Boolean(*GUSIExecFn)(const GUSIFileRef & ref);
extern GUSIExecFn GUSIExec;
Boolean GUSIDefaultExec(const GUSIFileRef & ref);
__END_DECLS